package com.tanhua.server.controller;

import com.tanhua.server.service.CommentsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {


    @Autowired
    private CommentsService commentsService;

    @GetMapping(value = "/likes",name = "分页查询对当前登录人圈子的点赞的人")
    public ResponseEntity likes(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
      return   commentsService.queryCommentPeople(page,pagesize,1);
    }

    @GetMapping(value = "/loves",name = "分页查询对当前登录人圈子的喜欢的人")
    public ResponseEntity loves(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return   commentsService.queryCommentPeople(page,pagesize,3);
    }


    @GetMapping(value = "/comments",name = "分页查询对当前登录人圈子的评论的人")
    public ResponseEntity comments(@RequestParam(defaultValue = "1") Integer page,
                                @RequestParam(defaultValue = "10") Integer pagesize){
        return   commentsService.queryCommentPeople(page,pagesize,2);
    }



//    聊一下添加好友
//    1、请求方式 Post
//    2、请求地址 /messages/contacts
//    3、请求参数 类型application/json  请求头上有Authorization
//       Body参数   {userId:2}
//     4、返回结果
    @PostMapping(value = "/contacts",name = "聊一下添加好友")
    public ResponseEntity contacts(@RequestBody Map param){
        Long userId = Long.parseLong( param.get("userId")+"" );
        return   commentsService.addContacts(userId);
    }

//    显示当前登录人好友列表
//    1、请求方式 get
//    2、请求地址 /messages/contacts
//    3、请求参数 类型application/json  请求头上有Authorization
//       Query参数   page  pagesize
//     4、返回结果 PageResult
    @GetMapping(value = "/contacts",name = "聊一下添加好友")
    public ResponseEntity queryContacts(@RequestParam(defaultValue = "1") Integer page,
                                        @RequestParam(defaultValue = "10")  Integer pagesize){
        return   commentsService.queryContacts(page,pagesize);
    }


}
